package com.matt.controller.pad;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;
import com.matt.foundation.constant.RequestConstant;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.foundation.query.ClassesCoursePlanQuery;
import com.matt.foundation.utils.JsonValidateUtil;
import com.matt.foundation.vo.course.CoursePlanEarlyListVo;
import com.matt.foundation.vo.course.PadCoursePlanDetailVo;
import com.matt.foundation.vo.course.PadTeacherCoursePlanListVo;
import com.matt.service.CourseEarlyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.matt.foundation.constant.RequestConstant.TICKET;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/11
 * *******************************
 */
@RestController
@RequestMapping("/pad/course_early")
public class PadCourseEarlyController {

    @Autowired
    private CourseEarlyService courseEarlyService;

    @Autowired
    private MemVerificationCache cache;


    @RequestMapping("/plan_list")
    public StatusResponse planList(@RequestHeader(TICKET) String ticket, ClassesCoursePlanQuery query) {
        StaffDTO baseInfo = cache.getStaff(ticket);
        query.setAreaId(baseInfo.getAreaId());
        query.setStaffId(baseInfo.getId());

        Page<PadTeacherCoursePlanListVo> teacherCoursePlanListVoList = courseEarlyService.getPadAllCoursePlan(query, false);
        return StatusResponse.success(teacherCoursePlanListVoList);
    }

    @RequestMapping("/history_list")
    public StatusResponse historyList(@RequestHeader(TICKET) String ticket, ClassesCoursePlanQuery query) {
        StaffDTO baseInfo = cache.getStaff(ticket);
        query.setStaffId(baseInfo.getId());
        query.setAreaId(baseInfo.getAreaId());
//        Boolean isTestUser = ssoCallService.getIsTestUser(baseInfo.getId());
        Page<PadTeacherCoursePlanListVo> coursePlanNurseryList = courseEarlyService.getPadHistoryCoursePlan(query, false);
        return StatusResponse.success(coursePlanNurseryList);
    }

    @RequestMapping("/plan_detail")
    public StatusResponse planDetail(String planId) {
        PadCoursePlanDetailVo vo = courseEarlyService.getEarlyCourseDetail(planId);
        return StatusResponse.success(vo);
    }

//    /**
//     * 宝宝上课签到
//     * @param ticket
//     * @param childrenCourseItemId
//     * @param status
//     * @param remark
//     * @return
//     */
//    @RequestMapping("/check_in")
//    public StatusResponse checkIn(@RequestHeader(TICKET) String ticket, String childrenCourseItemId, Integer status, String remark){
//        Map response = childrenCourseService.checkIn(cache.getStaffId(ticket), childrenCourseItemId, status, remark);
//        return StatusResponse.success(response);
//    }

    /**
     * 开始上课
     *
     * @param ticket
     * @param childrenCourseStatusJson
     * @return
     */
    @RequestMapping("/begin_course")
    public StatusResponse beginCourse(@RequestHeader(TICKET) String ticket, String childrenCourseStatusJson, String[] teacherIds, String coursePlanClassesId) {
        StaffDTO staff = cache.getStaff(ticket);
        JsonValidateUtil.validateChildrenCourseStatus(childrenCourseStatusJson);
        List list = JsonValidateUtil.readToList(childrenCourseStatusJson, "学生状态Json解析错误");
        Boolean result = courseEarlyService.beginCourse(staff, list, teacherIds, coursePlanClassesId);
        return StatusResponse.success(result);
    }


    @RequestMapping("/today_plan_list")
    public StatusResponse todayPlanList(@RequestHeader(TICKET) String ticket, String classId,ClassesCoursePlanQuery query) {
        StaffDTO baseInfo = cache.getStaff(ticket);
        query.setAreaId(baseInfo.getAreaId());
        query.setStaffId(baseInfo.getId());
        query.setClassId(classId);

        Page<PadTeacherCoursePlanListVo> teacherCoursePlanListVoList = courseEarlyService.getPadTodayCoursePlan(query, false);
        return StatusResponse.success(teacherCoursePlanListVoList);
    }

    @RequestMapping("/week_plan_list")
    public StatusResponse weekPlanList(@RequestHeader(TICKET) String ticket, String classId,ClassesCoursePlanQuery query) {
        StaffDTO baseInfo = cache.getStaff(ticket);
        query.setAreaId(baseInfo.getAreaId());
        query.setStaffId(baseInfo.getId());
        query.setClassId(classId);

        Page<PadTeacherCoursePlanListVo> teacherCoursePlanListVoList = courseEarlyService.getPadWeekCoursePlan(query, false);
        return StatusResponse.success(teacherCoursePlanListVoList);
    }

    @RequestMapping("/plan_by_date")
    public StatusResponse planByDate(@RequestHeader(RequestConstant.TICKET) String ticket, String areaId, String beginDate, String endDate) {
        List<CoursePlanEarlyListVo> coursePlans = courseEarlyService.getPlanByAreaBetweenDays(beginDate, endDate, areaId);
        return StatusResponse.success(coursePlans);
    }
}
